package guestbook;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class GuestbookServlet extends HttpServlet {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -7759593256585062849L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
//		resp.setContentType("text/plain");
//		resp.getWriter().println("Hello, world");
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
		if(user !=null)
		{
			resp.setContentType("text/plain");
			resp.getWriter().println("Hello, :::: "+user.getNickname());
			log("-------------- 1");
		}
		else{
			resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
			log("-------------- 2");
		}
	}
}
